<template>
  <div>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="130px" class="demo-ruleForm" size="mini">
      <el-form-item label="时间名称" prop="name">
        <el-input v-model="ruleForm.name" placeholder="请输入时间名称" clearable></el-input>
      </el-form-item>


      <el-form-item label="早上" >
        <el-time-picker
          is-range
          arrow-control
          v-model="ruleForm.morning"
          range-separator="至"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          placeholder="选择时间范围">
        </el-time-picker>
      </el-form-item>



      <el-form-item label="中午" prop="outSchoolDate">
        <el-time-picker
          is-range
          arrow-control
          v-model="ruleForm.noon"
          range-separator="至"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          placeholder="选择时间范围">
        </el-time-picker>
      </el-form-item>


      <el-form-item label="下午" prop="outSchoolDate">
        <el-time-picker
          is-range
          arrow-control
          v-model="ruleForm.afternoon"
          range-separator="至"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          placeholder="选择时间范围">
        </el-time-picker>
      </el-form-item>

      <el-form-item label="晚上" prop="outSchoolDate">
        <el-time-picker
          is-range
          arrow-control
          v-model="ruleForm.night"
          range-separator="至"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          placeholder="选择时间范围">
        </el-time-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">{{$t("action.save")}}</el-button>
        <el-button @click="resetForm('ruleForm')">{{$t("action.reset")}}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
    export default {
        name: "edit",
        data() {
            return {
                ruleForm: {
                    name: '',//时间名称
                    morning:'',//早上
                    noon:'',//中午
                    afternoon:'',//下午
                    night:'',//晚上
                },
                rules: {
                    name: [
                        {required: true, message: '请输入时间名称', trigger: 'blur'},
                        {min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur'}
                    ],

                }
            };
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        alert('submit!');
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
                this.ruleForm.morning='';
                this.ruleForm.noon='';
                this.ruleForm.afternoon='';
                this.ruleForm.night='';
            }
        }

    }
</script>

<style scoped lang="scss">
  .el-select, .el-date-editor {
    width: 100%;
  }

</style>
